#pragma once
#include "datastruct.h"

class Game;
class ResourceManager;
class AnimaObj 
{
	UINT ID;
	int FullWidth;
	double TimeLastFrame;
	LONGLONG LastTicks;
	double Speed;//delay of frames
	bool ToLeft;
protected:
	int nFrame;
	int NowFrame;
	HBITMAP hBm; //image list
	HBITMAP hBmFlip; //ToLeft image list
	bool IncreaseFrame(bool Loop_i);
	void SetCurrentFrame(int nF)		{NowFrame= nF; XSrc = (nF-1) * WidthSrc;	}

public:
	int XSrc, YSrc, WidthSrc, HeightSrc;
	int X, Y, Width, Height;
	bool Loop;

	virtual void Load(int id, int nFrame_i);
	virtual void Draw();
	void Unload();

	bool IncreaseFrameByTime(double Time, bool Loop_i = true);
	void FacingLeft();

	bool IsAnimFinished(){return (NowFrame == nFrame);}

	bool IsFaceLeft(){return ToLeft;}
	void SetSpeed(int FPS)		{Speed = 1.0/(double)FPS;}
	void ResetFrame() { SetCurrentFrame(1);}

protected:
	AnimaObj();
};


const int nFtrObj = 14;
const int MaxObj_Idx	= 12;
const int ObjectArrayLast = MaxObj_Idx + 1;

const int MaxFNameLen =  15;// Fighter Name
const int MaxBNameLen =  7;//Bkgnd Name


class ObjectInfo{
public:
	int nFighter;//maximal 10
	WCHAR	FName[nFtrObj][MaxFNameLen + 1];

	int nBkgnd;//maximal 10
	WCHAR	BName[nFtrObj][MaxBNameLen + 1];

	ObjectInfo(ResourceManager* RM);
};


//string operators
struct SO{
	static void Skip1(PWCHAR& p){p++;}
	static bool IsBS(PWCHAR& p){return (*p==L' ');}
	static bool IsEndLine(PWCHAR& p){ return (*p == 0 || *p == 0x000A);}
	static bool IsEndFile(PWCHAR& p){return (*p == 0);}

	static void Move2BS(PWCHAR& p){
		while(!IsBS(p) && !IsEndLine(p))
			Skip1(p);
	}

	static void Move2NextWord(PWCHAR& p){
		while(!IsBS(p) && !IsEndLine(p)) Move2BS(p); 
		if(!IsEndLine(p))
			Skip1(p);
	}

	static void Move2NextLine(PWCHAR& p){
		while(!IsEndLine(p)) Skip1(p); 
		Skip1(p);
	}

};

#define W	G.MW
